<?php
/*
+ --------------------------------------------------- +
|  Ineo Article Manager - Version 2.x
|  Copyright 2006-2007, Dan Cryer and William McGann
+ --------------------------------------------------- +

Ineo Article Manager is free software; you can redistribute it and/or modify
it under the terms of version 3 of the GNU General Public License as published by
the Free Software Foundation.

Ineo Article Manager is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with Ineo; see the file License.txt.  If not, write to
the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.

*/

/**
* Ineo - Modules - Articles
*  
* This module handles all front-end actions related to articles.
*
* @package		Ineo
* @subpackage   Modules
* @author		Dan Cryer & William McGann
* @copyright	Dan Cryer & William McGann
* @version		1.0.0
*/
class ineo_mod_article
{
	var $ipsclass;
	var $core;

	/**
	* Load article libraries
	*/
	function module_init()
	{
		$this->core->load_library('global');
		$this->core->load_library('articles');
		
		$this->lib_global =& $this->core->libs['global'];
		$this->lib_art    =& $this->core->libs['articles'];

		$this->core->load_template('articles');
	}

	function view()
	{
		$this->core->load_library('categories');
		
		/**
		* Support for text-based article ID's:
		*/
		if ( !is_numeric( $this->ipsclass->input['showarticle'] ) )
		{
			$artid = $this->get_article_by_text_id( $this->ipsclass->input['showarticle'] );

			if( $artid == false )
			{
				// We probably had multiple, and shown a search page!
				return;
			}
		}
		else
		{
			$artid = intval( $this->ipsclass->input['id'] );
		}

		/**
		* This one speaks for itself. Pulls article information and puts it on a page for your viewin' pleasure.
		*/
		$article = $this->core->libs['articles']->get_article( $artid );

		// If it's a queued article and the member isn't a mod, error 'em out.
		if ( $article['article_is_queued'] == '1' && $this->ipsclass->member['g_ineo_ismod'] == '0' )
		{
			$this->core->error( 'ineo_artview_queued' );
			return;
		}

		// If article doesn't exist, this prevents a nasty SQL error.
		if ( !$article )
		{
			$this->core->error( 'ineo_artiview_noart' );
			return;
		}
		
		// Check permissions for viewing this article:
		if( !$this->core->permissions->check_with_error('view',$article['category_id']) )
		{
			return;
		}

		$this->core->title .= ' - ' . $article['article_title'];

		$this->core->libs['categories']->build_nav_tree( $article['category_id'] );
		$this->core->libs['global']->nav_add( $article['article_title'], $this->core->libs['global']->make_article_url( $article['article_id'], $article['article_text_id'] ), 1 );

		// Creating dates from timestamps.
		$dates = array( 'created_date' => $this->ipsclass->get_date( $article['article_created_date'], '' ),'edited_date' => $this->ipsclass->get_date( $article['article_edited_date'], '' ) );
		
		// Split the article if needs be.
		$page = ( isset( $this->ipsclass->input['st'] ) ) ? intval( $this->ipsclass->input['st'] ) : 0 ;
		$split = $this->core->libs['articles']->multipage_split( $article['content_content'] );
		$article['content_content'] = ( $split == false ) ? $article['content_content'] : $split[ $page ] ;
		
		// Add article pagination, Zee-oh-myawesome!
		if ( $split != false )
		{
			$art_pagelinks = $this->ipsclass->build_pagelinks( array( 'TOTAL_POSS' => $split['page'] - 1,
					'PER_PAGE' => 1,
					'CUR_ST_VAL' => $page,
					'BASE_URL' => $this->core->libs['global']->make_article_url( $article['article_id'], $article['article_text_id'] ) ) );
		}
		
		$art_pagelinks = ( $this->ipsclass->vars['ineo_friendly_enable'] == 1 ) ? str_replace( '&amp;', '?', $art_pagelinks ) : $art_pagelinks ;
		$article['pagelinks'] = $art_pagelinks;
		
		// Hand the article's content to the application for parsing
		$body = $this->core->api->display_parse( $article['content_content'], true, $article['article_attach_key'] );

		// Determine what the article views value should be set to, then do eet on shutdown.
		$article['article_views'] = $article['article_views'] + 1;
		$this->ipsclass->DB->do_update( 'ineo_articles', array( 'article_views' => $article['article_views'] ), 'article_id = ' . $this->ipsclass->input['id'], true );

		$topic_link = $this->topic_manager( $article );
		
		$this->core->out .= $this->core->templates['articles']->article_index($article,$dates,$body,$topic_link,$resources);

		if ( $this->ipsclass->vars['ineo_rating'] == 1 )
		{
			// Pull voter information.
			$this->ipsclass->DB->simple_construct( array( 'select' => 'sum( rate_rating ) as rating_total, count( rate_rating ) as rating_count','from' => 'ineo_rating','where' => 'rate_artid = '.$article['article_id'] ) );
			$this->ipsclass->DB->simple_exec();
			$rate_data = $this->ipsclass->DB->fetch_row();

			$this->ipsclass->DB->simple_construct( array( 'select' => '*', 'from' => 'ineo_rating', 'where' => 'rate_artid = '.$article['article_id'].' AND rate_mid = '.$this->ipsclass->member['id'] ));
			$this->ipsclass->DB->simple_exec();
			$mrate_data = $this->ipsclass->DB->fetch_row();

			$rating = ( $rate_data['rating_count'] == 0 ) ? 0 : $rate_data['rating_total'] / $rate_data['rating_count'] ;
			$stars = $this->core->templates['global']->rating_stars(round($rating,0),'');

			$rate_data['total_rating'] = round($rating,0);

			$rate_box = "<div id='ineo-rate-options'>" .  $this->core->templates['articles']->rating_box($mrate_data,$rate_data,$stars) . '</div>';
			$this->core->menu .= $rate_box;

			///
			/// todo: add ratings to the sidebar, somehow!
			///
		}

		// Set created by info:
		/**
		* @todo We needs to fix this... IPB-only linkage going on.
		* @todo We also need to add article-author-name or something
		*/
		if ( $article['article_author'] == 0 )
		{
			$sec = "<b>" . $this->ipsclass->lang['ineo_created_by'] . ":</b> <i>" . $article['members_display_name'] ."</i>
			<br /><b>{$this->ipsclass->lang['ineo_on']}:</b> " . $dates['created_date'];
		}
		else
		{
			$sec = "<b>" . $this->ipsclass->lang['ineo_created_by'] . ":</b> " .
			"<a href='{$this->ipsclass->base_url}showuser={$article['article_author']}'>" .
			$article['members_display_name'] .
			"</a>
			<br />
			<b>{$this->ipsclass->lang['ineo_on']}:</b> " . $dates['created_date'];
		}

		// Set edited by info:
		if( !empty( $article['last_edited_by'] ) )
		{
			/**
			* @todo We needs to fix this... IPB-only linkage going on.
			*/
			if ( $article['article_edited_by'] == 0 )
			{
				$sec .= "<br /><br /><b>" . $this->ipsclass->lang['ineo_last_edited_by'] . ":</b> <i>" . $article['last_edited_by'] . "</i>" .
				"<br /><b>{$this->ipsclass->lang['ineo_on']}:</b> {$dates['edited_date']}";
			}
			else
			{
				$sec .= "<br /><br /><b>" . $this->ipsclass->lang['ineo_last_edited_by'] . ":</b> " .
				"<a href='{$this->ipsclass->base_url}showuser={$article['article_edited_by']}'>" .
				$article['last_edited_by'] . "</a>" .
				"<br /><b>{$this->ipsclass->lang['ineo_on']}:</b> {$dates['edited_date']}";
			}
		}

		// Set view info:
		$sec .= "<br /><br /><b>{$this->ipsclass->lang['ineo_views']}:</b> {$article['article_views']}";
	}
    
	/**
	* This function check for the existance of a topic, makes the links accordingly.
	*/
	function topic_manager($article)
	{
		if( !$this->ipsclass->vars['ineo_dtopics'] )
		{
			return false; 
		}
		
		// Whee!
		if( $article['article_tid'] != '0' )
		{
			// We have a topic, load it:
			$this->ipsclass->DB->simple_construct( array('select' => 'title' , 'from' => 'topics' , 'where' => 'tid = ' . $article['article_tid']) );
			$this->ipsclass->DB->simple_exec();

			if( $this->ipsclass->DB->get_num_rows() == 0 )
			{
				$this->ipsclass->DB->do_update( 'ineo_articles' , array( 'article_tid' => '0' ) , 'article_id = ' . $article['article_id'] );
				$topic_link = $this->ipsclass->lang['ineo_topic_noexist'].' <a id=\'ineo-topic-create\' href=\'{ipb.script_url}autocom=ineo&mod=xml&op=forward_to_create_topic\'>'.$this->ipsclass->lang['ineo_topic_create'].'</a>?';
				$article['article_tid'] = '0';
			}
			else
			{
				$topic = $this->ipsclass->DB->fetch_row();

				$topic_link = "<b>".$this->ipsclass->lang['ineo_discuss_on']."</b> <a id='ineo-topic-view' href='{$this->ipsclass->base_url}showtopic=".$article['article_tid']."'>{$topic['title']}</a>";
			}

			return $topic_link;
		}

	}

	/**
	* This function loads the editors, populates 'em, does all kinds of happy junk
	*/
	function edit()
	{
		// Load article info:
		$article = $this->lib_art->load_edit_data( $this->ipsclass->input['id'] );
		
		// Check permissions for editing this article:
		if( !$this->core->permissions->check_with_error('edit',$article['category_id']) )
		{
			return;
		}
		
		// Make sure the content is parsed for the editor:
		$article['content_content'] = $this->core->api->editor_parse($article['content_content']);
		// Add nav info:
		$this->core->libs['global']->nav_add( $article['article_title'] , $this->core->libs['global']->make_article_url( $article['article_id'], $article['article_text_id'] ), 1 );
		$this->core->libs['global']->nav_add( $this->ipsclass->lang['ineo_art_edit'] , 'mod=article&op=edit&id=' . $article['article_id'] );

		// Load lang_post & skin_post for the editor / attach system:
		$this->ipsclass->load_language('lang_post');
		$this->ipsclass->load_template('skin_post');

		// Get a list of possible categories:
		$categories = $this->core->libs['global']->category_dropdown( $article['article_cat_id'] );

		// Generate a unique key for attachments:
		$key = md5(uniqid(microtime().mt_rand(0, 100000)));

		// Set up editor:
		require_once( ROOT_PATH."sources/handlers/han_editor.php" );
		$han_editor = new han_editor();
		$han_editor->ipsclass =& $this->ipsclass;
		$han_editor->init();
		$editor_html = $han_editor->show_editor( $article['content_content'] , 'article_content' );

		// Set up attachment system:
		$key = $article['article_attach_key'];
		$attach_html = $this->core->templates['skin_post']->Upload_field($key,"ineo",$key,$key);

		// Form URL:
		$url = $this->core->base_url . 'mod=article&op=edit_sub';
		
		// Set up array of information for our post screen:
		$post_data = array(
		'action_key'          => $this->core->libs['global']->generate_csrf_key('edit'),
		'article_description' => $article['article_description'],
		'article_title'       => $article['article_title'],
		'article_id'          => $article['article_id'],
		'attach_html'         => $attach_html,
		'attach_key'          => $key,
		'category_dropdown'   => $categories,
		'editor_html'         => $editor_html,
		'type'                => 'edit',
		'url'                 => $url
		);
		
		$this->core->out .= $this->core->templates['articles']->post_form($post_data);
	}
	
	/**
	* This will be der submittin' der edit
	* Since it's so closely tied to the application it'll be running with, edit submission
	* will reside mainly in the appropriate api file.
	*/
	function edit_sub()
	{
		if ( isset( $this->ipsclass->input['guestname'] ) )
		{
			$data['guestname'] = $this->ipsclass->input['guestname'];
		}
		
		$csrf = $this->core->libs['global']->generate_csrf_key('edit');
		
		if( $this->ipsclass->input['action_key'] != $csrf )
		{
			$this->core->error( 'ineo_perm_error_text' );
			return;
		}
		
		$data['id']               = $this->ipsclass->input['article_id'];
		$data['article_content']  = $_POST['article_content']; // MUST USE RAW POST, ELSE WILL BORK AND EFF ITSELF
		$data['title']            = $this->ipsclass->input['article_title'];
		$data['description']      = $this->ipsclass->input['article_description'];
		$data['category']         = $this->ipsclass->input['category'];
		//$data['article_links']    = $this->ipsclass->input['article_links'];
		$data['article_links'] = '';
		$this->lib_art->full_edit( $data );
		

		// Check to see if the category changed during edit.
		// If so, alert members who have the new category on their watchlist.
		if ( $_POST['cat_check'] != $data['category'] )
		{
			$this->lib_global->watchlist_alert( $data['category'], 2, $data['id'] );
		}

		if ( $this->lib_art->edit_is_queued )
		{
			$this->ipsclass->boink_it( $this->core->base_url . 'showarticle=' . $data['id'] . '&msg=ineo_rev_queued' );
		}
		else
		{
			$this->lib_global->watchlist_alert( $data['id'], 1 );
			$this->ipsclass->boink_it( $this->core->base_url . 'showarticle=' . $data['id'] );
		}
	}
	
	
	/**
	* This is pretty obvious... however...
	* Pull the article ids of non-queued articles, then pick one at random, and boink to it!
	*/
	function random()
	{
		$array = array( 
						'select' => 'count(article_id) as cnt_max',
						'from'   => 'ineo_articles',
						'where'  => 'article_is_queued = \'0\'',
						);
		
		$this->ipsclass->DB->simple_construct( $array );
		$this->ipsclass->DB->simple_exec();
		
		$ooo = $this->ipsclass->DB->fetch_row();
		
		$rand_max = $ooo['cnt_max'];
		
		$rand = rand( 0 , $rand_max-1 );
		
		$array = array( 
						'select' => 'article_id,article_text_id',
						'from'   => 'ineo_articles',
						'where'  => 'article_is_queued = \'0\'',
						);
						
		$this->ipsclass->DB->simple_construct( $array );
		$this->ipsclass->DB->simple_limit($rand,1);
		$this->ipsclass->DB->simple_exec();
		
		$article = $this->ipsclass->DB->fetch_row();
		$id = $article['article_id'];
		
		$this->ipsclass->boink_it( $this->core->libs['global']->make_article_url( $article['article_id'], $article['article_text_id'] ) );
	}
	
	/**
	* Delete Article and Bounce to the index.
	*/
	function delete()
	{
		$id = $this->ipsclass->input['id'];
		$this->lib_art->delete_article( intval($id) );	
		$this->ipsclass->boink_it( $this->core->base_url . 'msg=ineo_deleted' );
	}
	
	/**
	* @todo Make it not fugly, and borked.
	*/
	function printable()
	{
	  //----
	  // Create a simple, printable version of an article
	  //----
	  
    $this->ipsclass->DB->simple_construct( array( 'select' => 'a.*, c.*, m.members_display_name, e.members_display_name as last_edited_by',
                                                  'from' => array( 'ineo_articles' => 'a'),
                                                  'add_join' => array( 1 =>
                                                                array( 'type' => 'left',
                                                                       'from' => array( 'ineo_content' => 'c'),
                                                                       'where' => 'c.content_id=a.article_content'
                                                                     ),
                                                                       2 =>
                                                                array( 'type' => 'left',
                                                                       'from' => array( 'members' => 'm' ),
                                                                       'where' => 'm.id=a.article_author'
                                                                     ),
                                                                       3 =>
                                                                array( 'type' => 'left',
                                                                       'from' => array( 'members' => 'e' ),
                                                                       'where' => 'e.id=a.article_edited_by'
                                                                     )
                                                                     ),                                                                 
                                                  'where' => 'a.article_id = ' . $this->ipsclass->input['id']
                                                  ) );
	  $article = $this->ipsclass->DB->simple_exec();
	  $article = $this->ipsclass->DB->fetch_row( $article );
	  
	  $article['content_content'] = $this->core->api->display_parse($article['content_content']);
	
		die($this->core->templates['articles']->print_version($article));
	}
	
	function create()
	{
		// Load lang_post & skin_post for the editor / attach system:
		$this->ipsclass->load_language('lang_post');
		$this->ipsclass->load_template('skin_post');
		
		// Get a list of possible categories:
		$categories = $this->core->libs['global']->category_dropdown();
		
		// Generate a unique key for attachments:
		$key = md5(uniqid(microtime().mt_rand(0, 100000)));
		
		// Set up editor:
		require_once( ROOT_PATH."sources/handlers/han_editor.php" );
		$han_editor = new han_editor();
		$han_editor->ipsclass =& $this->ipsclass;
		$han_editor->init();
		$editor_html = $han_editor->show_editor( '' , 'article_content' );
		
		// Set up attachment system:
		$attach_html = $this->core->templates['skin_post']->Upload_field($key,"ineo",$key,$key);
		
		// Form URL:
		$url = $this->core->base_url . 'mod=article&op=add';
		
		// Set up array of information for our post screen:
		$post_data = array(
		'action_key'          => $this->core->libs['global']->generate_csrf_key('create'),
		'article_description' => '',
		'article_id'          => 0,
		'article_title'       => '',
		'attach_html'         => $attach_html,
		'attach_key'          => $key,
		'category_dropdown'   => $categories,
		'editor_html'         => $editor_html,
		'type'                => 'create',
		'url'                 => $url
		);
		
		$this->core->out .= $this->core->templates['articles']->post_form($post_data);
	}
	
	function new_art()
	{
		$this->create();
	}
	
	function add()
	{
		// Make sure that if we're a guest, we have a guest name
		// and if we're not, we set our member ID as the author.
		if( $this->ipsclass->member['id'] == 0 )
		{
			if( !empty($this->ipsclass->input['guestname']) )
			{
				$author = $this->ipsclass->input['guestname'];
			}
			else
			{
				$this->core->global->error('NO GUEST NAME','YOU MUST ENTER A GUEST NAME');
			}
		}
		else
		{
			$author = $this->ipsclass->member['id'];
		}
		
		// Define variables for creation of the article:
		$title    = $this->ipsclass->input['article_title'];
		$desc     = $this->ipsclass->input['article_description'];
		$category = intval( $this->ipsclass->input['category'] );
		$text_id  = $this->core->libs['global']->make_text_id( $title, $category );
		$att_key  = preg_replace('/([^a-zA-Z0-9])/','',$this->ipsclass->input['attach_key']);
		
		// Clean out the title and description:
		$desc  = strip_tags( $desc );
		$title = strip_tags( $title );
		
		// No title? No article.
		if ( empty($title) )
		{
			$this->core->error( 'ineo_notopic_error' );
			return;
		}
		
		// Check that this isn't some kind of session hijack:
		$csrf = $this->core->libs['global']->generate_csrf_key('create');
		
		if( $this->ipsclass->input['action_key'] != $csrf )
		{
			$this->core->error( 'ineo_perm_error_text' );
			return;
		}
		
		/*
		// Load the editor handler:
		require_once( ROOT_PATH."sources/handlers/han_editor.php" );
		$han_editor           = new han_editor();
		$han_editor->ipsclass =& $this->ipsclass;
		$han_editor->init();

		require_once( ROOT_PATH . 'sources/handlers/han_parse_bbcode.php' ); 
		$parse                      = new parse_bbcode();
		$parse->ipsclass            =& $this->ipsclass;
		$parse->allow_update_caches = 1;
		$parse->bypass_badwords     = intval($this->ipsclass->member['g_bypass_badwords']);
		$parse->parse_smilies       = 1;
		$parse->parse_bbcode        = 1;		

		if( $han_editor->method == 'rte' )
		{
			$_POST['article_content'] = $parse->convert_ipb_html_to_html( $_POST['article_content'] );
		}*/

		$queued = ( $this->ipsclass->member['g_ineo_queue'] == '0' && $this->ipsclass->vars['ineo_queue_new'] == '1' ) ? '1' : '0';
		
		$insert = 
		array(
		'article_title' => $title,
		'article_text_id'      => $text_id,
		'article_description'  => $desc,
		'article_cat_id'       => $category,
		'article_content'      => 0,
		'article_author'       => $author,
		'article_created_date' => time(),
		'article_edited_date'  => time(),
		'article_is_queued'    => $queued,
		'article_attach_key'   => $att_key);

		$this->ipsclass->DB->do_insert( 'ineo_articles' , $insert );

		// Get insert ID for the article:
		$art_id = $this->ipsclass->DB->get_insert_id();

		$insert2 = array('content_article' => $art_id,'content_author'  => $author,'content_date'    => time());

		// Fully formatted and ready to insert
		$insert2['content_content'] = $this->core->api->database_parse( $_POST['article_content'] );    					

		$this->ipsclass->DB->do_insert( 'ineo_content' , $insert2 );

		// Get insert ID for the article:
		$cont_id = $this->ipsclass->DB->get_insert_id();
		$this->set_article_content( $art_id , $cont_id );

		// Check to see if article has been queued. If so, redirect to ineo index w/system message.
		$this->ipsclass->DB->simple_construct( array( 'select' => 'article_is_queued', 'from' => 'ineo_articles', 'where' => 'article_id = '.$art_id ) );
		$this->ipsclass->DB->simple_exec();
		$data = $this->ipsclass->DB->fetch_row();

		if ( $data['article_is_queued'] == 1 )
		{
			$this->ipsclass->boink_it( $this->core->base_url . 'msg=ineo_new_queued' );
		}
		else
		{
			// Call the article creation complete event:
			$this->core->events->article_create_complete($art_id,$category);
			
			// Redirect to the article:
			$this->ipsclass->boink_it( $this->core->libs['global']->make_article_url( $art_id, $text_id ) );
		}
	}
	
	function set_article_content( $article_id , $content_id )
	{
		$this->ipsclass->DB->do_update( 'ineo_articles' , array( 'article_content' => $content_id ) , 'article_id = \'' . $article_id . '\'' );
	}
	
	function diff()
	{
    require_once( KERNEL_PATH.'class_difference.php' );
    $this->ipsclass->difference = new class_difference();
    $this->ipsclass->difference->ipsclass =& $this->ipsclass;
    
	  $this->ipsclass->DB->simple_construct( array( 'select' => 'content_content, content_article',
	                                                'from' => 'ineo_content',
	                                                'where' => 'content_id = ' . $this->ipsclass->input['id'] ) );
    $this->ipsclass->DB->simple_limit( 1 );
	  $check = $this->ipsclass->DB->simple_exec();
	  $content = $this->ipsclass->DB->fetch_row($check);
	  
	  $this->ipsclass->DB->simple_construct( array( 'select' => 'a.article_content, a.article_title, a.article_id, a.article_text_id, c.content_content',
	                                                'from' => array( 'ineo_articles' => 'a' ),
	                                                'add_join' => array( 1 => array(
	                                                              'type' => 'left',
	                                                              'from' => array( 'ineo_content' => 'c' ),
	                                                              'where' => 'c.content_id = a.article_content' ) ),
	                                                'where' => 'a.article_id = ' . $content['content_article'] ) );
    $this->ipsclass->DB->simple_limit( 1 );
	  $check = $this->ipsclass->DB->simple_exec();
	  $article = $this->ipsclass->DB->fetch_row($check);
	  
	  $html = $this->ipsclass->difference->get_differences( $content['content_content'] , $article['content_content'] );
	  $html = html_entity_decode($html);
	  
	  /**
	  * @todo Please please please add language bits!
	  */
	  $this->core->nav_add( $article['article_title'], $this->core->libs['global']->make_article_url( $article['article_id'], $article['article_text_id'] ) );
	  $this->core->nav_add( 'DIFF REPORT', 'mod=article&op=diff&id=' . $this->ipsclass->input['id'] );
	  
    $this->core->out .= $this->core->templates['articles']->diff_report($html);
	}
	
	/**
	* Get Article By Text Id
	*/
	function get_article_by_text_id( $incoming )
	{
		$title = str_replace( $this->ipsclass->vars['ineo_friendly_suffix'], '', $this->ipsclass->input['showarticle'] );
		
		$select_array = array(
								'select' => 'article_id', 
								'from'   => 'ineo_articles', 
								'where'  => 'article_text_id = \''.$title.'\'' 
							  );
		
  		$this->ipsclass->DB->simple_construct( $select_array );
  		$this->ipsclass->DB->simple_exec();
  		  		  		
  		if ( $this->ipsclass->DB->get_num_rows() == 1 )
  		{
	  		$data = $this->ipsclass->DB->fetch_row();
  			return $data['article_id'];
  		}
  		elseif ( $this->ipsclass->DB->get_num_rows() > 1 )
  		{
			$tids = '0';
			while( $res = $this->ipsclass->DB->fetch_row() )
			{
				$tids .= ',' . $res['article_id'];
			}
			
  			$this->list_textid_matches($tids);
  		}
  		else
  		{
  			$this->core->error( 'ineo_artiview_noart' );
  			return;
  		}
	}
	
	function list_textid_matches( $in )
	{
		$select_array = array('select' => '*', 'from'   => 'ineo_articles', 'where'  => 'article_id IN ('.$in.')' );
		
		$this->ipsclass->DB->simple_construct( $select_array );
	  	$this->ipsclass->DB->simple_exec();
	
		$articles = array();
		while( $res = $this->ipsclass->DB->fetch_row() )
		{
			$res['article_date'] = $this->ipsclass->get_date($res['article_edited_date'],'');
			$res['article_link'] = $this->core->libs['global']->make_article_url( $res['article_id'], $res['article_text_id'] );
			$articles[] = $res;
		}
			
		$this->core->out .= $this->core->templates['global']->search_results($articles);
	}
}

?>